@echo off
setlocal enabledelayedexpansion

REM get batch file directory
for %%i in ("%~dp0.") do set "BATCH_DIR=%%~fi"

REM get batch file arguments
set "opt=%*"

cd /d "%BATCH_DIR%"

echo shell dir: %BATCH_DIR%, arguments: %opt%

setup() {
  echo setup starting...
  mvn clean verify -Dmaven.test.skip=true && ./setup-cli/setup-cli.bat db create && ./setup-cli/setup-cli.bat db migrate
  echo done!
}

reset() {
  echo reset starting...
  mvn clean verify -Dmaven.test.skip=true && ./setup-cli/setup-cli.bat db drop && ./setup-cli/setup-cli.bat db create && ./setup-cli/setup-cli.bat db migrate
  echo done!
}

migrate() {
  echo migrate starting...
  mvn clean verify -Dmaven.test.skip=true && ./setup-cli/setup-cli.bat db migrate
  echo done!
}

jooq() {
  echo jooq starting...
  mvn clean verify -Dmaven.test.skip=true && ./setup-cli/setup-cli.bat gen jooq
  echo done!
}

build() {
  echo build skip test starting...
  mvn clean verify -Dmaven.test.skip=true
  echo done!
}

_test() {
  echo test starting...
  mvn clean test
  echo done!
}

echo Running %1 command as %USERNAME%

if "%1"=="setup" (
  call :setup
) else if "%1"=="reset" (
  call :reset
) else if "%1"=="migrate" (
  call :migrate
) else if "%1"=="jooq" (
  call :jooq
) else if "%1"=="build" (
  call :build
) else if "%1"=="test" (
  call :_test
) else (
  echo Usage: %0 {setup^|migrate^|jooq^|build^|test}
  exit /b 1
)

exit /b 0

:setup
setup
exit /b

:reset
reset
exit /b

:migrate
migrate
exit /b

:jooq
jooq
exit /b

:build
build
exit /b

:_test
_test
exit /b